﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MvcControlsToolkit
{
    public class PlotOptions : BaseObject
    {
        public PlotType Type
        {
            get
            {
                if (Attributes.ContainsKey("renderer"))
                {
                    switch (Attributes["renderer"])
                    {
                        case "jQuery.jqplot.LineRenderer": return PlotType.Line;
                        case "jQuery.jqplot.BarRenderer": return PlotType.Bar;
                        case "jQuery.jqplot.BubbleRenderer": return PlotType.Bubble;
                        case "jQuery.jqplot.PieRenderer": return PlotType.Pie;
                        default: return PlotType.Line;
                    }
                }
                else
                    return PlotType.Line;
            }

            set
            {
                switch (value)
                {
                    case PlotType.Line: Attributes["renderer"] = "jQuery.jqplot.LineRenderer"; break;
                    case PlotType.Bar: Attributes["renderer"] = "jQuery.jqplot.BarRenderer"; break;
                    case PlotType.Bubble: Attributes["renderer"] = "jQuery.jqplot.BubbleRenderer"; break;
                    case PlotType.Pie: Attributes["renderer"] = "jQuery.jqplot.PieRenderer"; break;
                }
            }
        }

        public bool Shadow
        {
            get
            {
                if (Attributes.ContainsKey("shadow"))
                    return Boolean.Parse(GetString("shadow"));
                else
                    return true;
            }
            set
            {
                Attributes["shadow"] = value.ToString().ToLower();
            }
        }

        public bool FillToZero
        {
            get
            {
                if (Attributes.ContainsKey("fillToZero"))
                    return Boolean.Parse(GetString("fillToZero"));
                else
                    return true;
            }
            set
            {
                Attributes["fillToZero"] = value.ToString().ToLower();
            }
        }

        public bool Fill
        {
            get
            {
                if (Attributes.ContainsKey("fill"))
                    return Boolean.Parse(GetString("fill"));
                else
                    return true;
            }

            set
            {
                Attributes["fill"] = value.ToString().ToLower();
            }
        }

        private string rendererOptions
        {
            get { return Attributes["rendererOptions"]; }
            set { Attributes["rendererOptions"] = value; }
        }

        private string pointLabels
        {
            get { return Attributes["pointLabels"]; }
            set { Attributes["pointLabels"] = value; }
        }

        public PlotOptions SetRendererOptions(object rendererOptions)
        {
            this.rendererOptions = rendererOptions.ToString();

            return this;
        } 

        public PlotOptions SetPointLabels(PointLabels pointLabels)
        {
            this.pointLabels = pointLabels.ToString();

            return this;
        }
    }
}
